<template>
    <common-layout>
        <div class="top">
            <div class="header">
                <img alt="logo" class="logo" src="@/assets/img/logo.png" />
                <span class="title">{{systemName}}</span>
            </div>
            <div class="desc">OSS登陆中...</div>
        </div>
    </common-layout>
</template>

<script>
import CommonLayout from '@/layouts/CommonLayout'
import {getRoutesConfig,queryUserInfo} from '@/services/user'
import {setAuthorization} from '@/utils/request'
import {loadRoutes} from '@/utils/routerUtil'
import {mapMutations} from 'vuex'

export default {
    name: 'Oss',
    components: {CommonLayout},
    data () {
        return {
            logging: false,
            error: ''
        }
    },

    computed: {
        systemName () {
            return this.$store.state.setting.systemName
        }
    },
    methods: {
        ...mapMutations('account', ['setUser', 'setPermissions', 'setRoles']),
        doSsoLogin(){
            let geturl = window.location.href

            let getqyinfo = geturl.split('?')[1]
            let getqys = getqyinfo.split('&')
            let obj = {}  //创建空对象，接收截取的参数
            for(let i = 0;i < getqys.length;i++ ){
                console.log(i)
                let item = getqys[i].split('=')
                let key = item[0]
                let value = item[1]
                obj[key] = value
            }
            console.log(obj)
            setAuthorization({token: obj["token"], refreshToken: obj["token"]})
            queryUserInfo().then((r)=>{
                const ur=r.data
                const {user, permissions, roles} = ur.data
                this.setUser(user)
                this.setPermissions(permissions)
                this.setRoles(roles)
                //setAuthorization({token: loginRes.data.token, expireAt: new Date(loginRes.data.expireAt)})
            })
            // 获取路由配置
            getRoutesConfig().then(result => {
                const routesConfig = result.data.data
                loadRoutes(routesConfig)
                this.$router.push('/dashboard/workplace')
                this.$message.success(result.message, 3)
            })

        }
    },
    created() {
        this.doSsoLogin()
    }
}
</script>

<style lang="less" scoped>
.common-layout{
  .top {
    text-align: center;
    .header {
      height: 44px;
      line-height: 44px;
      a {
        text-decoration: none;
      }
      .logo {
        height: 44px;
        vertical-align: top;
        margin-right: 16px;
      }
      .title {
        font-size: 33px;
        color: @title-color;
        font-family: 'Myriad Pro', 'Helvetica Neue', Arial, Helvetica, sans-serif;
        font-weight: 600;
        position: relative;
        top: 2px;
      }
    }
    .desc {
      font-size: 14px;
      color: @text-color-second;
      margin-top: 12px;
      margin-bottom: 40px;
    }
  }
  .login{
    width: 368px;
    margin: 0 auto;
    @media screen and (max-width: 576px) {
      width: 95%;
    }
    @media screen and (max-width: 320px) {
      .captcha-button{
        font-size: 14px;
      }
    }
    .icon {
      font-size: 24px;
      color: @text-color-second;
      margin-left: 16px;
      vertical-align: middle;
      cursor: pointer;
      transition: color 0.3s;

      &:hover {
        color: @primary-color;
      }
    }
  }
}
</style>
